#include <jni.h>
#include <string>
#include <vector>
#include "face_sdk.hpp"
//
// Created by yeqing on 2023/5/8.
//
using namespace FaceSDK;

extern "C"
JNIEXPORT jstring JNICALL
Java_com_bagus_mediapipefacedetection_jni_FaceDetectJni_startDetectFace(JNIEnv *env, jobject thiz,
                                                                        jdoubleArray points_array) {
    std::string result = detect2(env, points_array);
    return env->NewStringUTF(result.c_str());
}

extern "C"
JNIEXPORT jdoubleArray JNICALL
Java_com_bagus_mediapipefacedetection_jni_FaceDetectJni_detectFinish(JNIEnv *env, jobject thiz,
                                                                     jdoubleArray points_array) {
    std::vector<double> result = detectFinish(env,points_array);
    jdoubleArray output = env->NewDoubleArray( result.size() );
    env->SetDoubleArrayRegion( output, 0, result.size(), &result[0] );
    return output;
}

extern "C"
JNIEXPORT jfloatArray JNICALL
Java_com_bagus_mediapipefacedetection_jni_FaceDetectJni_nativeStartDetect(JNIEnv *env, jobject thiz,
                                                                          jdoubleArray points_array,
                                                                          jint width, jint height) {
    std::vector<float> result = detect3(env, points_array,width,height);
    jfloatArray output = env->NewFloatArray( result.size() );
    env->SetFloatArrayRegion( output, 0, result.size(), &result[0] );
    return output;
}

extern "C"
JNIEXPORT jfloatArray JNICALL
Java_com_bagus_mediapipefacedetection_jni_FaceDetectJni_nativeDetect(JNIEnv *env, jobject thiz,
                                                                     jobject source1,
                                                                     jdoubleArray points_array,
                                                                     jint width, jint height) {
    cv::Mat srcImg1 = convertBitmp2Mat(env,source1);//图片转化成mat
    std::vector<float> result = detect(env, srcImg1,points_array,width,height);
    jfloatArray output = env->NewFloatArray( result.size() );
    env->SetFloatArrayRegion( output, 0, result.size(), &result[0] );
    return output;
}